package com.bestcem.xm.ticket.service.convert;

import com.bestcem.xm.ticket.controller.param.ticket.TransferTicketParam;
import com.bestcem.xm.ticket.enums.TicketTemplateFieldNameEnum;
import com.bestcem.xm.ticket.enums.TicketTypeEnum;
import com.bestcem.xm.ticket.service.manager.record.param.FollowedTicketRecordParam;
import com.bestcem.xm.ticket.service.manager.record.param.TransferParam;
import com.bestcem.xm.ticket.service.manager.record.param.TransferTicketRecordParam;

import java.util.LinkedHashMap;

/**
 * @author liheng
 * @version v1.0
 * @date 2021/9/14 18:15
 */

public class TicketRecordConvert {
    private TicketRecordConvert() {
    }

    public static FollowedTicketRecordParam paramToFollow(TransferParam param) {
        if (param == null) {
            return null;
        }
        FollowedTicketRecordParam followedTicketRecordParam = new FollowedTicketRecordParam();

        followedTicketRecordParam.setOrgId(param.getOrgId());
        followedTicketRecordParam.setRoleId(param.getRoleId());
        followedTicketRecordParam.setUserId(param.getUserId());
        followedTicketRecordParam.setUserName(param.getUserName());
        followedTicketRecordParam.setRegionName(param.getRegionName());
        followedTicketRecordParam.setTicketId(param.getTicketId());
        followedTicketRecordParam.setSource(param.getSource());
        followedTicketRecordParam.setTitle(param.getTitle());
        followedTicketRecordParam.setContent(param.getContent());
        followedTicketRecordParam.setStatus(param.getStatus());
        followedTicketRecordParam.setType(param.getType());
        followedTicketRecordParam.setReason(param.getReason());
        followedTicketRecordParam.setIsCompleted(param.getIsCompleted());
        followedTicketRecordParam.setTemplateId(param.getTemplateId());
        followedTicketRecordParam.setTemplateFields(param.getTemplateFields());
        LinkedHashMap<TicketTemplateFieldNameEnum, String> linkedHashMap = param.getFieldMap();

        if (linkedHashMap != null) {
            followedTicketRecordParam.setFieldMap(new LinkedHashMap<>(linkedHashMap));
        }
        return followedTicketRecordParam;
    }

    public static TransferTicketRecordParam paramToRecordParam(TransferTicketParam param) {
        if (param == null) {
            return null;
        }
        TransferTicketRecordParam result = new TransferTicketRecordParam();

        // 操作人的组织id, 返回结果后, 上层方法中手动设置, 不过这个字段不存
        result.setRegionId(null);
        // 操作人的组织, 返回结果后, 上层方法中手动设置
        result.setRegionName(null);

        // 在转派记录的处理方法里会有固定值填充, 这里不写
        result.setSource(null);
        result.setTitle(null);
        result.setStatus(null);
        // 跟进/审核 自定义字段, 不用
        result.setContent(null);
        // 转派记录不存这个
        result.setRoleId(null);

        // 工单
        result.setType(TicketTypeEnum.NEED_DEAL);
        // 工单id
        result.setTicketId(param.getTicketId());
        // 租户id
        result.setOrgId(param.getOrgId());
        // 转派原因
        result.setReason(param.getReason());
        // 转派类型
        result.setFollowFilter(param.getUserFilter());
        // 执行转派人的Id
        result.setUserId(param.getDispatcherId());
        // 执行转派人的姓名
        result.setUserName(param.getDispatcher());


        // 接受转派工单的人的Id
        result.setReceiveUserId(param.getUserId());
        // 接受转派工单的人的名字
        result.setReceiveUsername(param.getUsername());

        // 接受工单转派的人角色Id
        result.setReceiveRoleId(param.getRoleId());
        // 接受工单转派的人角色名字
        result.setReceiveRoleName(param.getRoleName());
        // 接受转派工单的组织id
        result.setReceiveGroupId(param.getGroupId());
        // 接受转派工单的组织名字
        result.setReceiveGroupName(param.getGroupName());
        // 接受转派工单的组织的层级id
        result.setReceiveGroupLevelId(param.getGroupLevelId());
        // 接受转派工单的组织的层级名字
        result.setReceiveGroupLevelName(param.getGroupLevelName());

        return result;
    }
}
